/* Gluten Library -- VectorTests
 *
 * Performs tests on Vector functionality.
 *
 * $AUTHOR$    res
 * $UPDATE$    r32
 */

/* LICENSES ********************************************************************

Copyright (c) 2013- Reuben E. Smith

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

*******************************************************************************/


#ifndef GLUTEN_VECTORTESTS_HPP
#define GLUTEN_VECTORTESTS_HPP

#include <cassert>
#include <iostream>
#include "Gluten/Vector.hpp"

#define PERFORM_TEST(N) \
   std::cout << "VectorTests::test" #N "()" << std::endl; \
   assert(test##N())


namespace Gluten
{
   // res: Not really sure what a good value for this is... 6% error seems to
   //      work for now. (Need to test this on more systems.)
   static const float FAST_EPSILON = 0.06f;


   class VectorTests
   {
   public:
      VectorTests()
      {
         std::cout << "Performing Vector tests"
      #ifndef VECTOR_NO_SIMD
                 << " (with SIMD variants)"
      #else
                 << " (without SIMD variants)"
      #endif
                 << std::endl;

         PERFORM_TEST(CreateDefault);
         PERFORM_TEST(CreateCopy);
         PERFORM_TEST(CreateValues);
         PERFORM_TEST(AssignmentOp);
         PERFORM_TEST(EqualityOp);
         PERFORM_TEST(InequalityOp);
         PERFORM_TEST(ReadDimOp);
         PERFORM_TEST(WriteDimOp);
         PERFORM_TEST(NormSquare);
         PERFORM_TEST(Norm);
         PERFORM_TEST(Normal);
         PERFORM_TEST(Normalize);
         PERFORM_TEST(Dot);
         PERFORM_TEST(Cross);
         PERFORM_TEST(CloneOp);
         PERFORM_TEST(AddVector);
         PERFORM_TEST(AddScalar);
         PERFORM_TEST(AddScalarVector);
         PERFORM_TEST(LocalAddVector);
         PERFORM_TEST(LocalAddScalar);
         PERFORM_TEST(NegatedOp);
         PERFORM_TEST(SubVector);
         PERFORM_TEST(SubScalar);
         PERFORM_TEST(SubScalarVector);
         PERFORM_TEST(LocalSubVector);
         PERFORM_TEST(LocalSubScalar);
         PERFORM_TEST(MulVector);
         PERFORM_TEST(MulScalar);
         PERFORM_TEST(MulScalarVector);
         PERFORM_TEST(LocalMulVector);
         PERFORM_TEST(LocalMulScalar);
         PERFORM_TEST(DivVector);
         PERFORM_TEST(DivScalar);
         PERFORM_TEST(DivScalarVector);
         PERFORM_TEST(LocalDivVector);
         PERFORM_TEST(LocalDivScalar);
      }


      bool testCreateDefault()
      {
         bool r = false;

         Vector<2, int> a;
         r = (a._d[0] == 0 && a._d[1] == 0);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> b;

         r = r && (
            b._d[0] == 0 &&
            b._d[1] == 0 &&
            b._d[2] == 0 &&
            b._d[3] == 0);
      #endif

         return r;
      }


      bool testCreateCopy()
      {
         bool r = false;

         Vector<2, int> a;
         a._d[0] = 5;
         Vector<2, int> b(a);

         r = (b._d[0] == a._d[0] && b._d[1] == a._d[1]);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> c;
         c._d[0] = 5;
         c._d[3] = 2;
         Vector<4, float> d(c);

         r = r && 
            (d._d[0] == c._d[0]) &&
            (d._d[1] == c._d[1]) &&
            (d._d[2] == c._d[2]) &&
            (d._d[3] == c._d[3]);
      #endif

         return r;
      }


      bool testCreateValues()
      {
         bool r = false;
         const int values[2] = { 2, 4 };

         Vector<2, int> a(values);

         r = (a._d[0] == values[0] && a._d[1] == values[1]);

      #ifndef VECTOR_NO_SIMD
         const float fvalues[4] = { 1, 3, 5, 7 };

         Vector<4, float> b(fvalues);
         
         r = r && (
            b._d[0] == fvalues[0] &&
            b._d[1] == fvalues[1] &&
            b._d[2] == fvalues[2] &&
            b._d[3] == fvalues[3]);
      #endif

         return r;
      }


      bool testAssignmentOp()
      {
         bool r = false;

         Vector<2, int> a;
         a._d[0] = 1;
         a._d[1] = 2;
         Vector<2, int> b;
         b = a;

         r = (b._d[0] == a._d[0] && b._d[1] == a._d[1]);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> c;
         c._d[0] = 1;
         c._d[1] = 2;
         c._d[2] = 3;
         c._d[3] = 4;
         Vector<4, float> d;
         d = c;

         r = r && (
            d._d[0] == c._d[0] &&
            d._d[1] == c._d[1] &&
            d._d[2] == c._d[2] &&
            d._d[3] == c._d[3]);
      #endif

         return r;
      }


      bool testEqualityOp()
      {
         bool r = false;

         Vector<2, int> a;
         a._d[0] = 1;
         a._d[1] = 2;
         Vector<2, int> b;
         b._d[0] = 1;
         b._d[1] = 2;
         Vector<2, int> c;
         c._d[0] = 0;
         c._d[1] = 0;

         r = ((a == b) && !(a == c));

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> d;
         d._d[0] = 1.f;
         d._d[3] = 2.f;
         Vector<4, float> e;
         e._d[0] = 1.f;
         e._d[3] = 2.f;
         Vector<4, float> f;
         f._d[0] = 0.f;
         f._d[3] = 0.f;

         r = r && 
            ((d == e) && !(d == f));
      #endif

         return r;
      }


      bool testInequalityOp()
      {
         bool r = false;

         Vector<2, int> a;
         a._d[0] = 1;
         a._d[1] = 2;
         Vector<2, int> b;
         b._d[0] = 1;
         b._d[1] = 2;
         Vector<2, int> c;
         c._d[0] = 0;
         c._d[1] = 0;

         r = (!(a != b) && (a != c));

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> d;
         d._d[0] = 1;
         d._d[3] = 2;
         Vector<4, float> e;
         e._d[0] = 1;
         e._d[3] = 2;
         Vector<4, float> f;
         f._d[0] = 0;
         f._d[3] = 0;

         r = r && 
            (!(d != e) && (d != f));
      #endif

         return r;
      }


      bool testReadDimOp()
      {
         bool r = false;

         Vector<2, int> a;
         a._d[1] = 4;

         r = (a(1) == 4);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> b;
         b._d[3] = 4;

         r = r && (b(3) == 4);
      #endif

         return r;
      }


      bool testWriteDimOp()
      {
         bool r = false;

         Vector<2, int> a;
         a(1) = 5;

         r = (a._d[1] == 5);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> b;
         b(3) = 5;

         r = r && (b._d[3] == 5);
      #endif

         return r;
      }


      bool testNormSquare()
      {
         bool r = false;

         Vector<2, int> a;
         a._d[0] = 3;
         a._d[1] = 3;

         r = (a.normSquare() == 18);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> b;
         b._d[0] = 3;
         b._d[3] = 3;

         r = r && (b.normSquare() == 18);
      #endif

         return r;
      }


      bool testNorm()
      {
         bool r = false;

         Vector<2, int> a;
         a._d[0] = 3;
         a._d[1] = 3;

      #ifndef VECTOR_FAST_MATH
         r = (a.norm() == static_cast<int>(std::sqrt(18.0f)));
      #else
         r = std::abs(1 - 
            (a.norm() / static_cast<int>(std::sqrt(18.0f)))) < FAST_EPSILON;
      #endif

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> b;
         b._d[0] = 3;
         b._d[3] = 3;

         #ifndef VECTOR_FAST_MATH
            r = r && (fpRelativeEqual(b.norm(), std::sqrt(18.0f)));
         #else
            r = r &&
               (std::abs(1 - (a.norm() / std::sqrt(18.0f))) < FAST_EPSILON);
         #endif
      #endif

         return r;
      }


      bool testNormal()
      {
         bool r = false;

         Vector<2, int> a;
         a._d[0] = 0;
         a._d[1] = 1;

         // WARN relies on copy constructor
         Vector<2, int> b(a.normal());

         r = (b._d[0] == 0 && b._d[1] == 1);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> c;
         c._d[0] = 0;
         c._d[1] = 1;
         c._d[2] = 1;
         c._d[3] = 0;

         // WARN relies on copy constructor
         Vector<4, float> d(c.normal());

         #ifndef VECTOR_FAST_MATH
            r = r &&
               (d._d[0] == 0 && 
                fpRelativeEqual(d._d[1], 0.7071067f) &&
                fpRelativeEqual(d._d[2], 0.7071067f) &&
                d._d[3] == 0);
         #else
            r = r &&
               (d._d[0] == 0 &&
                std::abs(1 - (d._d[1] / 0.7071067f)) < FAST_EPSILON &&
                std::abs(1 - (d._d[2] / 0.7071067f)) < FAST_EPSILON &&
                d._d[3] == 0);
         #endif
      #endif

         return r;
      }


      bool testNormalize()
      {
         bool r = false;

         Vector<2, int> a;
         a._d[0] = 0;
         a._d[1] = 1;
         a.normalize();

         r = (a._d[0] == 0 && a._d[1] == 1);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> c;
         c._d[0] = 0;
         c._d[1] = 1;
         c._d[2] = 1;
         c._d[3] = 0;
         c.normalize();

         #ifndef VECTOR_FAST_MATH
            r = r &&
               (c._d[0] == 0 && 
                fpRelativeEqual(c._d[1], 0.7071067f) &&
                fpRelativeEqual(c._d[2], 0.7071067f) &&
                c._d[3] == 0);
         #else
            r = r &&
               (c._d[0] == 0 &&
                std::abs(1 - (c._d[1] / 0.7071067f)) < FAST_EPSILON &&
                std::abs(1 - (c._d[2] / 0.7071067f)) < FAST_EPSILON &&
                c._d[3] == 0);
         #endif
      #endif

         return r;
      }


      bool testDot()
      {
         bool r = false;

         Vector<2, int> a, b;
         a._d[0] = 1;
         a._d[1] = 2;
         b._d[0] = 3;
         b._d[1] = 4;

         r = (a.dot(b) == 11) && (b.dot(a) == 11);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> c, d;
         c._d[0] = 1;
         c._d[3] = 2;
         d._d[0] = 3;
         d._d[3] = 4;

         #ifndef VECTOR_FAST_MATH
            r = r &&
               (fpRelativeEqual(c.dot(d), 11.0f) && 
                fpRelativeEqual(d.dot(c), 11.0f));
         #else
            r = r &&
               (std::abs(1 - (c.dot(d) / 11.0f)) < FAST_EPSILON &&
                std::abs(1 - (d.dot(c) / 11.0f)) < FAST_EPSILON);
         #endif
      #endif

         return r;
      }


      bool testCross()
      {
         bool r = false;

         Vector<3, int> a, b;
         a._d[1] = 1;
         b._d[0] = 1;

         Vector<3, int> c(a.cross(b)), d(b.cross(a));

         r = (c._d[0] == 0 && c._d[1] == 0 && c._d[2] == -1) &&
             (d._d[0] == 0 && d._d[1] == 0 && d._d[2] == 1);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> e, f;
         e._d[1] = 1;
         f._d[0] = 1;

         Vector<4, float> g(e.cross(f)), h(f.cross(e));

         r = r &&
            (g._d[0] == 0 && g._d[1] == 0 && 
             g._d[2] == -1 && g._d[3] == 0) &&
            (h._d[0] == 0 && h._d[1] == 0 && 
             h._d[2] == 1 && h._d[3] == 0);
      #endif

         return r;
      }


      bool testCloneOp()
      {
         bool r = false;

         Vector<2, int> a;
         a._d[0] = 1;
         a._d[1] = 2;

         // WARN relies on copy constructor and LocalAddScalar
         Vector<2, int> b((+a) += 1);

         r = (b._d[0] == 2 && b._d[1] == 3) &&
             (a._d[0] == 1 && a._d[1] == 2);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> c;
         c._d[0] = 1;
         c._d[3] = 2;

         // WARN relies on copy constructor and LocalAddScalar
         Vector<4, float> d((+c) += 1);

         r = r &&
             (d._d[0] == 2 && d._d[1] == 1 && d._d[2] == 1 && d._d[3] == 3) &&
             (c._d[0] == 1 && c._d[1] == 0 && c._d[2] == 0 && c._d[3] == 2);
      #endif

         return r;
      }


      bool testAddVector()
      {
         bool r = false;

         Vector<2, int> a, b;
         a._d[0] = 1;
         a._d[1] = 2;
         b._d[0] = 3;
         b._d[1] = 4;

         // WARN relies on copy constructor
         Vector<2, int> c(a + b);

         r = (c._d[0] == 4 && c._d[1] == 6) &&
            (a._d[0] == 1 && a._d[1] == 2) &&
            (b._d[0] == 3 && b._d[1] == 4);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> d, e;
         d._d[0] = 1;
         d._d[1] = 2;
         e._d[0] = 3;
         e._d[1] = 4;

         // WARN relies on copy constructor
         Vector<4, float> f(d + e);

         r = r && 
            (f._d[0] == 4 && f._d[1] == 6 &&
             f._d[2] == 0 && f._d[3] == 0) &&
            (d._d[0] == 1 && d._d[1] == 2 &&
             d._d[2] == 0 && d._d[3] == 0) &&
            (e._d[0] == 3 && e._d[1] == 4 &&
             e._d[2] == 0 && e._d[3] == 0);
      #endif

         return r;
      }


      bool testAddScalar()
      {
         bool r = false;

         Vector<2, int> a;
         a._d[0] = 1;
         a._d[1] = 2;

         // WARN relies on copy constructor
         Vector<2, int> c(a + 10);

         r = (c._d[0] == 11 && c._d[1] == 12) &&
            (a._d[0] == 1 && a._d[1] == 2);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> d;
         d._d[0] = 1;
         d._d[1] = 2;

         // WARN relies on copy constructor
         Vector<4, float> f(d + 10);

         r = r && 
            (f._d[0] == 11 && f._d[1] == 12 &&
             f._d[2] == 10 && f._d[3] == 10);
            (d._d[0] == 1 && d._d[1] == 2 &&
             d._d[2] == 0 && d._d[3] == 0);
      #endif

         return r;
      }


      bool testAddScalarVector()
      {
         bool r = false;

         Vector<2, int> a;
         a._d[0] = 1;
         a._d[1] = 2;

         // WARN relies on copy constructor
         Vector<2, int> c(10 + a);

         r = (c._d[0] == 11 && c._d[1] == 12) &&
            (a._d[0] == 1 && a._d[1] == 2);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> d;
         d._d[0] = 1;
         d._d[1] = 2;

         // WARN relies on copy constructor
         Vector<4, float> f(10 + d);

         r = r &&
            (f._d[0] == 11 && f._d[1] == 12 &&
             f._d[2] == 10 && f._d[3] == 10) &&
            (d._d[0] == 1 && d._d[1] == 2 &&
             d._d[2] == 0 && d._d[3] == 0);
      #endif

         return r;
      }


      bool testLocalAddVector()
      {
         bool r = false;

         Vector<2, int> a, b;
         a._d[0] = 1;
         a._d[1] = 2;
         b._d[0] = 3;
         b._d[1] = 4;

         a += b;

         r = (a._d[0] == 4 && a._d[1] == 6) &&
            (b._d[0] == 3 && b._d[1] == 4);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> c, d;
         c._d[0] = 1;
         c._d[1] = 2;
         d._d[0] = 3;
         d._d[1] = 4;

         c += d;

         r = r &&
            (c._d[0] == 4 && c._d[1] == 6 &&
             c._d[2] == 0 && c._d[3] == 0) &&
            (d._d[0] == 3 && d._d[1] == 4 &&
             d._d[2] == 0 && d._d[3] == 0);
      #endif

         return r;
      }


      bool testLocalAddScalar()
      {
         bool r = false;

         Vector<2, int> a;
         a._d[0] = 1;
         a._d[1] = 2;

         a += 10;

         r = (a._d[0] == 11 && a._d[1] == 12);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> c;
         c._d[0] = 1;
         c._d[1] = 2;

         c += 10;

         r = r &&
            (c._d[0] == 11 && c._d[1] == 12 &&
             c._d[2] == 10 && c._d[3] == 10);
      #endif

         return r;
      }


      bool testNegatedOp()
      {
         bool r = false;

         Vector<2, int> a;
         a._d[0] = 1;
         a._d[1] = 2;

         r = ((-a)._d[0] == -1 && (-a)._d[1] == -2);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> b;
         b._d[0] = 1;
         b._d[1] = 2;
         b._d[2] = 3;
         b._d[3] = 4;

         r = r &&
            ((-b)._d[0] == -1) &&
            ((-b)._d[1] == -2) &&
            ((-b)._d[2] == -3) &&
            ((-b)._d[3] == -4);
      #endif

         return r;
      }


      bool testSubVector()
      {
         bool r = false;

         Vector<2, int> a, b;
         a._d[0] = 1;
         a._d[1] = 2;
         b._d[0] = 3;
         b._d[1] = 4;

         // WARN relies on copy constructor
         Vector<2, int> c(a - b);

         r = (c._d[0] == -2 && c._d[1] == -2) &&
            (a._d[0] == 1 && a._d[1] == 2) &&
            (b._d[0] == 3 && b._d[1] == 4);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> d, e;
         d._d[0] = 1;
         d._d[1] = 2;
         e._d[0] = 3;
         e._d[1] = 4;

         // WARN relies on copy constructor
         Vector<4, float> f(d - e);

         r = r && 
            (f._d[0] == -2 && f._d[1] == -2 &&
              f._d[2] == 0 && f._d[3] == 0) &&
            (d._d[0] == 1 && d._d[1] == 2 &&
             d._d[2] == 0 && d._d[3] == 0) &&
            (e._d[0] == 3 && e._d[1] == 4 &&
             e._d[2] == 0 && e._d[3] == 0);
      #endif

         return r;
      }


      bool testSubScalar()
      {
         bool r = false;

         Vector<2, int> a;
         a._d[0] = 1;
         a._d[1] = 2;

         // WARN relies on copy constructor
         Vector<2, int> c(a - 10);

         r = (c._d[0] == -9 && c._d[1] == -8) &&
            (a._d[0] == 1 && a._d[1] == 2);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> d;
         d._d[0] = 1;
         d._d[1] = 2;

         // WARN relies on copy constructor
         Vector<4, float> f(d - 10);

         r = r && 
            (f._d[0] == -9 && f._d[1] == -8 &&
             f._d[2] == -10 && f._d[3] == -10) &&
            (d._d[0] == 1 && d._d[1] == 2 &&
             d._d[2] == 0 && d._d[3] == 0);
      #endif

         return r;
      }


      bool testSubScalarVector()
      {
         bool r = false;

         Vector<2, int> a;
         a._d[0] = 1;
         a._d[1] = 2;

         // WARN relies on copy constructor
         Vector<2, int> c(10 - a);

         r = (c._d[0] == 9 && c._d[1] == 8) &&
            (a._d[0] == 1 && a._d[1] == 2);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> d;
         d._d[0] = 1;
         d._d[1] = 2;

         // WARN relies on copy constructor
         Vector<4, float> f(10 - d);

         r = r &&
            (f._d[0] == 9 && f._d[1] == 8 && 
             f._d[2] == 10 && f._d[3] == 10) &&
            (d._d[0] == 1 && d._d[1] == 2 &&
             d._d[2] == 0 && d._d[3] == 0);
      #endif

         return r;
      }


      bool testLocalSubVector()
      {
         bool r = false;

         Vector<2, int> a, b;
         a._d[0] = 1;
         a._d[1] = 2;
         b._d[0] = 3;
         b._d[1] = 4;

         a -= b;

         r = (a._d[0] == -2 && a._d[1] == -2) &&
            (b._d[0] == 3 && b._d[1] == 4);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> c, d;
         c._d[0] = 1;
         c._d[1] = 2;
         d._d[0] = 3;
         d._d[1] = 4;

         c -= d;

         r = r &&
            (c._d[0] == -2 && c._d[1] == -2 &&
             c._d[2] == 0 && c._d[3] == 0) &&
            (d._d[0] == 3 && d._d[1] == 4 &&
             d._d[2] == 0 && d._d[3] == 0);
      #endif

         return r;
      }


      bool testLocalSubScalar()
      {
         bool r = false;

         Vector<2, int> a;
         a._d[0] = 1;
         a._d[1] = 2;

         a -= 10;

         r = (a._d[0] == -9 && a._d[1] == -8);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> c;
         c._d[0] = 1;
         c._d[3] = 2;

         c -= 10;

         r = r &&
            (c._d[0] == -9) &&
            (c._d[1] == -10) &&
            (c._d[2] == -10) &&
            (c._d[3] == -8);
      #endif

         return r;
      }


      bool testMulVector()
      {
         bool r = false;

         Vector<2, int> a, b;
         a._d[0] = 1;
         a._d[1] = 2;
         b._d[0] = 3;
         b._d[1] = 4;

         // WARN relies on copy constructor
         Vector<2, int> c(a * b);

         r = (c._d[0] == 3 && c._d[1] == 8) &&
            (a._d[0] == 1 && a._d[1] == 2) &&
            (b._d[0] == 3 && b._d[1] == 4);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> d, e;
         d._d[0] = 1;
         d._d[1] = 2;
         e._d[0] = 3;
         e._d[1] = 4;

         // WARN relies on copy constructor
         Vector<4, float> f(d * e);

         r = r && 
            (f._d[0] == 3 && f._d[1] == 8 &&
             f._d[2] == 0 && f._d[3] == 0) &&
            (d._d[0] == 1 && d._d[1] == 2 &&
             d._d[2] == 0 && d._d[3] == 0) &&
            (e._d[0] == 3 && e._d[1] == 4 &&
             e._d[2] == 0 && e._d[3] == 0);
      #endif

         return r;
      }


      bool testMulScalar()
      {
         bool r = false;

         Vector<2, int> a;
         a._d[0] = 1;
         a._d[1] = 2;

         // WARN relies on copy constructor
         Vector<2, int> c(a * 10);

         r = (c._d[0] == 10 && c._d[1] == 20) &&
            (a._d[0] == 1 && a._d[1] == 2);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> d;
         d._d[0] = 1;
         d._d[1] = 2;

         // WARN relies on copy constructor
         Vector<4, float> f(d * 10);

         r = r && 
            (f._d[0] == 10 && f._d[1] == 20 &&
             f._d[2] == 0 && f._d[3] == 0) &&
            (d._d[0] == 1 && d._d[1] == 2 &&
             d._d[2] == 0 && d._d[3] == 0);
      #endif

         return r;
      }


      bool testMulScalarVector()
      {
         bool r = false;

         Vector<2, int> a;
         a._d[0] = 1;
         a._d[1] = 2;

         // WARN relies on copy constructor
         Vector<2, int> c(10 * a);

         r = (c._d[0] == 10 && c._d[1] == 20) &&
            (a._d[0] == 1 && a._d[1] == 2);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> d;
         d._d[0] = 1;
         d._d[1] = 2;

         // WARN relies on copy constructor
         Vector<4, float> f(10 * d);

         r = r &&
            (f._d[0] == 10 && f._d[1] == 20 && 
             f._d[2] == 0 && f._d[3] == 0) &&
            (d._d[0] == 1 && d._d[1] == 2 &&
             d._d[2] == 0 && d._d[3] == 0);
      #endif

         return r;
      }


      bool testLocalMulVector()
      {
         bool r = false;

         Vector<2, int> a, b;
         a._d[0] = 1;
         a._d[1] = 2;
         b._d[0] = 3;
         b._d[1] = 4;

         a *= b;

         r = (a._d[0] == 3 && a._d[1] == 8) &&
            (b._d[0] == 3 && b._d[1] == 4);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> c, d;
         c._d[0] = 1;
         c._d[1] = 2;
         d._d[0] = 3;
         d._d[1] = 4;

         c *= d;

         r = r &&
            (c._d[0] == 3 && c._d[1] == 8 &&
             c._d[2] == 0 && c._d[3] == 0) &&
            (d._d[0] == 3 && d._d[1] == 4 &&
             d._d[2] == 0 && d._d[3] == 0);
      #endif

         return r;
      }


      bool testLocalMulScalar()
      {
         bool r = false;

         Vector<2, int> a;
         a._d[0] = 1;
         a._d[1] = 2;

         a *= 10;

         r = (a._d[0] == 10 && a._d[1] == 20);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> c;
         c._d[0] = 1;
         c._d[3] = 2;

         c *= 10;

         r = r &&
            (c._d[0] == 10) &&
            (c._d[1] == 0) &&
            (c._d[2] == 0) &&
            (c._d[3] == 20);
      #endif

         return r;
      }


      bool testDivVector()
      {
         bool r = false;

         Vector<2, int> a, b;
         a._d[0] = 3;
         a._d[1] = 4;
         b._d[0] = 3;
         b._d[1] = 2;

         // WARN relies on copy constructor
         Vector<2, int> c(a / b);

         r = (c._d[0] == 1 && c._d[1] == 2) &&
            (a._d[0] == 3 && a._d[1] == 4) &&
            (b._d[0] == 3 && b._d[1] == 2);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> d, e;
         d._d[0] = 1;
         d._d[1] = 2;
         e._d[0] = 3;
         e._d[1] = 4;
         e._d[2] = 1;
         e._d[3] = 1;

         // WARN relies on copy constructor
         Vector<4, float> f(d / e);

         #ifndef VECTOR_FAST_MATH
            r = r && 
               (fpRelativeEqual(f._d[0], 0.333333f) && 
                fpRelativeEqual(f._d[1], 0.500000f) &&
                fpRelativeEqual(f._d[2], 0.0f) && 
                fpRelativeEqual(f._d[3], 0.0f)) &&
               (d._d[0] == 1 && d._d[1] == 2 &&
                d._d[2] == 0 && d._d[3] == 0) &&
               (e._d[0] == 3 && e._d[1] == 4 &&
                e._d[2] == 1 && e._d[3] == 1);
         #else
            r = r && 
               (std::abs(1 - (f._d[0] / 0.333333f)) < FAST_EPSILON && 
                std::abs(1 - (f._d[1] / 0.500000f)) < FAST_EPSILON &&
                std::abs(f._d[2]) < FAST_EPSILON && 
                std::abs(f._d[3]) < FAST_EPSILON) &&
               (d._d[0] == 1 && d._d[1] == 2 &&
                d._d[2] == 0 && d._d[3] == 0) &&
               (e._d[0] == 3 && e._d[1] == 4 &&
                e._d[2] == 1 && e._d[3] == 1);
         #endif
      #endif

         return r;
      }


      bool testDivScalar()
      {
         bool r = false;

         Vector<2, int> a;
         a._d[0] = 10;
         a._d[1] = 20;

         // WARN relies on copy constructor
         Vector<2, int> c(a / 10);

         r = (c._d[0] == 1 && c._d[1] == 2) &&
            (a._d[0] == 10 && a._d[1] == 20);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> d;
         d._d[0] = 1;
         d._d[1] = 2;

         // WARN relies on copy constructor
         Vector<4, float> f(d / 10.0f);

         #ifndef VECTOR_FAST_MATH
            r = r && 
               (fpRelativeEqual(f._d[0], 0.100000f) && 
                fpRelativeEqual(f._d[1], 0.200000f) &&
                f._d[2] == 0 && f._d[3] == 0) &&
               (fpRelativeEqual(d._d[0], 1.0f) && 
                fpRelativeEqual(d._d[1], 2.0f) &&
                d._d[2] == 0 && d._d[3] == 0);
         #else
            r = r && 
               (std::abs(1 - (f._d[0] / 0.1f)) < FAST_EPSILON && 
                std::abs(1 - (f._d[1] / 0.2f)) < FAST_EPSILON &&
                f._d[2] == 0 && f._d[3] == 0) &&
               (std::abs(1 - (d._d[0] / 1.0f)) < FAST_EPSILON && 
                std::abs(1 - (d._d[1] / 2.0f)) < FAST_EPSILON &&
                d._d[2] == 0 && d._d[3] == 0);
         #endif
      #endif

         return r;
      }


      bool testDivScalarVector()
      {
         bool r = false;

         Vector<2, int> a;
         a._d[0] = 1;
         a._d[1] = 2;

         // WARN relies on copy constructor
         Vector<2, int> c(10 / a);

         r = (c._d[0] == 10 && c._d[1] == 5) &&
            (a._d[0] == 1 && a._d[1] == 2);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> d;
         d._d[0] = 1;
         d._d[1] = 2;
         d._d[2] = 1;
         d._d[3] = 1;

         // WARN relies on copy constructor
         Vector<4, float> f(10 / d);

         #ifndef VECTOR_FAST_MATH
            r = r &&
               (fpRelativeEqual(f._d[0], 10.0f) && 
                fpRelativeEqual(f._d[1], 5.0f) && 
                fpRelativeEqual(f._d[2], 10.0f) &&
                fpRelativeEqual(f._d[3], 10.0f)) &&
               (d._d[0] == 1 && d._d[1] == 2 &&
                d._d[2] == 1 && d._d[3] == 1);
         #else
            r = r &&
               (std::abs(1 - (f._d[0] / 10.0f)) < FAST_EPSILON && 
                std::abs(1 - (f._d[1] / 5.0f)) < FAST_EPSILON && 
                std::abs(1 - (f._d[2] / 10.0f)) < FAST_EPSILON &&
                std::abs(1 - (f._d[3] / 10.0f)) < FAST_EPSILON) &&
               (d._d[0] == 1 && d._d[1] == 2 &&
                d._d[2] == 1 && d._d[3] == 1);
         #endif
      #endif

         return r;
      }


      bool testLocalDivVector()
      {
         bool r = false;

         Vector<2, int> a, b;
         a._d[0] = 6;
         a._d[1] = 8;
         b._d[0] = 3;
         b._d[1] = 4;

         a /= b;

         r = (a._d[0] == 2 && a._d[1] == 2) &&
            (b._d[0] == 3 && b._d[1] == 4);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> c, d;
         c._d[0] = 6;
         c._d[1] = 8;
         d._d[0] = 3;
         d._d[1] = 4;
         d._d[2] = 1;
         d._d[3] = 1;

         c /= d;

         #ifndef VECTOR_FAST_MATH
            r = r &&
               (fpRelativeEqual(c._d[0], 2.0f) && 
                fpRelativeEqual(c._d[1], 2.0f) &&
                fpRelativeEqual(c._d[2], 0.0f) &&
                fpRelativeEqual(c._d[3], 0.0f)) &&
               (d._d[0] == 3 && d._d[1] == 4 &&
                d._d[2] == 1 && d._d[3] == 1);
         #else
            r = r &&
               (std::abs(1 - (c._d[0] / 2.0f)) < FAST_EPSILON && 
                std::abs(1 - (c._d[1] / 2.0f)) < FAST_EPSILON && 
                std::abs(c._d[2]) < FAST_EPSILON &&
                std::abs(c._d[3]) < FAST_EPSILON) &&
               (d._d[0] == 3 && d._d[1] == 4 &&
                d._d[2] == 1 && d._d[3] == 1);
         #endif
      #endif

         return r;
      }


      bool testLocalDivScalar()
      {
         bool r = false;

         Vector<2, int> a;
         a._d[0] = 100;
         a._d[1] = 200;

         a /= 10;

         r = (a._d[0] == 10 && a._d[1] == 20);

      #ifndef VECTOR_NO_SIMD
         Vector<4, float> c;
         c._d[0] = 1;
         c._d[3] = 2;

         c /= 10;

         #ifndef VECTOR_FAST_MATH
            r = r &&
               fpRelativeEqual(c._d[0], 0.1f) &&
               (c._d[1] == 0) &&
               (c._d[2] == 0) &&
               fpRelativeEqual(c._d[3], 0.2f);
         #else
            r = r &&
               std::abs(1 - (c._d[0] / 0.1f)) < FAST_EPSILON &&
               (c._d[1] == 0) &&
               (c._d[2] == 0) &&
               std::abs(1 - (c._d[3] / 0.2f)) < FAST_EPSILON;
         #endif
      #endif

         return r;
      }
   };
}

#undef PERFORM_TEST

#endif
